//
//  UITableViewCell+HDMyCommunityCell.m
//  app
//
//  Created by D on 15/8/21.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDMyCommunityCell.h"

static const CGFloat kmargin = 12.0f;
static const CGFloat kNameWitd = 100.0f;
static const CGFloat kNameHight = 30.0f;

@interface HDMyCommunityCell ()
@property (nonatomic, strong) UILabel * communityName;
@property (nonatomic, strong) UILabel * houseName;
@end

@implementation  HDMyCommunityCell

#pragma mark - add by sn
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createCell];
    }
    return self;
}

- (void)createCell
{
    _communityName = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH - 20, kHDMyCommunityCellH * 0.5)];
    [_communityName setFont:[UIFont systemFontOfSize:14]];
    [_communityName setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
    [self.contentView addSubview:_communityName];
    
    _houseName = CREATE_WITH_FRAME_OF(UILabel, [_communityName.ufo fx:0 fy:1.0],
                                          [_communityName.ubo fw:1.0 fh:1.0]);
    [_houseName setFont:[UIFont systemFontOfSize:14]];
    [_houseName setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
    [self.contentView addSubview:_houseName];
}
#pragma mark - add end


-(void)cellWithModel:(HDMyCommunityModel *)model Row:(NSInteger)row
{
    
    #pragma mark - add by sn
    _communityName.text = [NSString stringWithFormat:@"所在小区：%@",model.community_name];
    if (model.selected.integerValue == 1) {
        
        UILabel * selectLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:1 ox:-kNameWitd-kmargin fy:UB_1_2 oy:-kNameHight/2], [self.ubo ow:kNameWitd oh:kNameHight])];
        selectLab.text = @"[当前选中]";
        [selectLab setFont:[UIFont systemFontOfSize:12]];
        [selectLab setTextAlignment:NSTextAlignmentRight];
        [selectLab setTextColor:[XCommon hexStringToColor:kColor_red_text]];
        //            selectLab.backgroundColor = [UIColor blueColor];
        [self addSubview:selectLab];
        
        NSString * currentAdd = [NSString stringWithFormat:@"%@,%@",model.community_name,model.house_name];
        
        NSArray *array = [model.house_name componentsSeparatedByString:@","];
        
        NSString * house_name = [array objectAtIndex:0];
        
        [[NSUserDefaults standardUserDefaults] setObject:currentAdd forKey:@"currentAdd_code"];
        [[NSUserDefaults standardUserDefaults] setObject:model.house_id forKey:@"currentCom"];
//        [[NSUserDefaults standardUserDefaults] setObject:model.community_name forKey:kMyAreaTitle];
        [[NSUserDefaults standardUserDefaults] setObject:house_name forKey:kMyAreaTitle];
        [[NSUserDefaults standardUserDefaults] setObject:model.cmid forKey:kMyAreaID];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
    }
    
    _houseName.text = [NSString stringWithFormat:@"单元楼号：%@",model.house_name];
    
    #pragma mark - add end
    
//    if (row == 0) {
//        CGFloat witd = [XCommon widthForString:model.community_name fontSize:16];
//        UILabel * communityName = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kmargin fy:UB_1_2 oy:-kNameHight/2], [self.ubo ow:kNameWitd+witd oh:kNameHight])];
//        communityName.text = [NSString stringWithFormat:@"所在小区：%@",model.community_name];
//        [communityName setFont:[UIFont systemFontOfSize:14]];
//        [communityName setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
//        [self addSubview:communityName];
//        
//        if (model.selected.integerValue == 1) {
//            
//            UILabel * selectLab = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:1 ox:-kNameWitd-kmargin fy:UB_1_2 oy:-kNameHight/2], [self.ubo ow:kNameWitd oh:kNameHight])];
//            selectLab.text = @"[当前选中]";
//            [selectLab setFont:[UIFont systemFontOfSize:12]];
//            [selectLab setTextAlignment:NSTextAlignmentRight];
//            [selectLab setTextColor:[XCommon hexStringToColor:kColor_red_text]];
////            selectLab.backgroundColor = [UIColor blueColor];
//            [self addSubview:selectLab];
//            
//            NSString * currentAdd = [NSString stringWithFormat:@"%@,%@",model.community_name,model.house_name];
//            
//            
//            [[NSUserDefaults standardUserDefaults] setObject:currentAdd forKey:@"currentAdd_code"];
//            [[NSUserDefaults standardUserDefaults] setObject:model.house_id forKey:@"currentCom"];
//            [[NSUserDefaults standardUserDefaults] setObject:model.community_name forKey:kMyAreaTitle];
//            [[NSUserDefaults standardUserDefaults] setObject:model.cmid forKey:kMyAreaID];
//            [[NSUserDefaults standardUserDefaults] synchronize];
//            
//        }
//        
//        
//        
//    }
//    else if (row == 1){
//    
//        CGFloat witd = [XCommon widthForString:model.house_name fontSize:16];
//        UILabel * houseName = [[UILabel alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kmargin fy:UB_1_2 oy:-kNameHight/2], [self.ubo ow:kNameWitd+witd oh:kNameHight])];
//        houseName.text = [NSString stringWithFormat:@"单元楼号：%@",model.house_name];
//        [houseName setFont:[UIFont systemFontOfSize:14]];
//        [houseName setTextColor:[XCommon hexStringToColor:kColor_gray_text]];
//        [self addSubview:houseName];
//    }

}

- (void)drawRect:(CGRect)rect
{
    [self drawBackground:rect color:[UIColor whiteColor]];
    [self drawHorizonLineLeft:10 right:10 at:kHDMyCommunityCellH * 0.5 - UP(0.5)];
}

@end
